#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
const int M = 1010;
typedef long long ll;
int N, L, K;
int k[M];
int mm[M];
vector<int> vc[M];
bool vis[M];
struct userID {
	int level;
	int id;
}user;
ll ans = 0;
void bfs(int id)
{
	queue<userID> q;
	user.level=1;
	user.id=id;
	q.push(user);
	while (!q.empty())
	{
		auto top = q.front();
		q.pop();
		int level = top.level;
		int id = top.id;
		for (int i = 0; i < vc[id].size(); i++)
		{
			if(!vis[vc[id][i]])
			{
			    vis[vc[id][i]]=true;
			    ans+=1;
			    if(level<L)
			    {
			        user.level=level+1;
			        user.id=vc[id][i];
			        q.push(user);
			    }
			}
		}
	}
}
int main()
{
	cin >> N >> L;
	for(int i=1;i<=N;i++)
	{
	    int x;
	    cin >> x;
	    for(int j=0;j<x;j++)
	    {
	        int s;
	        cin >> s;
	        vc[s].push_back(i);
	    }
	}
	cin >> K;
	for (int i = 0; i < K; i++)
	{
		cin >> k[i];
	}
	for (int i = 0; i < K; i++)
	{
		ans = 0;
		memset(vis, false, sizeof vis);
		vis[k[i]] = true;
		bfs(k[i]);
		cout << ans << endl;
	}
	return 0;
}